class TimeUtils {
  ///根据时间转换为中文时间说辞
  static String getComparedTime(int dateTime) {
    // Duration difference = DateTime.now().difference(DateTime.parse(dateTime));
    Duration difference = DateTime.now()
        .difference(DateTime.fromMillisecondsSinceEpoch(dateTime * 1000));
    final List prefix = [
      "刚刚",
      "秒前",
      "分钟前",
      "小时前",
      "天前",
      "月前",
      "年前"
    ];
    if (difference.inDays == 0) {
      if (difference.inMinutes == 0) {
        if (difference.inSeconds < 20) {
          return (prefix[0]);
        } else {
          return ("${difference.inSeconds} ${prefix[1]}");
        }
      } else {
        if (difference.inMinutes > 59) {
          return ("${(difference.inMinutes / 60).floor()} ${prefix[3]}");
        } else {
          return ("${difference.inMinutes} ${prefix[2]}");
        }
      }
    } else {
      if (difference.inDays > 30) {
        if (((difference.inDays) / 30).floor() > 12) {
          return ("${((difference.inDays / 30) / 12).floor()} ${prefix[6]}");
        } else {
          return ("${(difference.inDays / 30).floor()} ${prefix[5]}");
        }
      } else {
        return ("${difference.inDays} ${prefix[4]}");
      }
    }
  }
  /// 获取时间，格式为HH:mm:ss(时分秒)
  /// param1- seconds:总秒数
  static String getHMmmss_Seconds(int seconds){
    int h = 0,m = 0,s = 0;String result = "";
    if(seconds <= 59){
      return "00:"+getDoubleStr(seconds);
    }else{
      m = seconds~/60;
      s = seconds % 60;
      if(m <= 59){
        return getDoubleStr(m)+":"+getDoubleStr(s);
      }else{
        h = m ~/ 60;
        m = m % 60;
        return getDoubleStr(h)+":"+getDoubleStr(m)+":"+getDoubleStr(s);
      }
    }
  }
  static String getDoubleStr(int num){
    try {
      if(num < 10){
        return "0"+num.toString();
      }else{
        return num.toString();
      }
    } catch (e) {
      return "00";
    }
  }

}
